package com.example.xloong.mymvvm.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.view.ViewGroup;


import com.example.xloong.mymvvm.BR;
import com.example.xloong.mymvvm.R;
import com.example.xloong.mymvvm.base.BaseAdapter;
import com.example.xloong.mymvvm.base.BaseViewHolder;
import com.example.xloong.mymvvm.bean.NewsBeanSimple;

/**
 * Created by Xloong on 2018/1/26.
 */

public class NewsAdapter extends BaseAdapter<NewsBeanSimple,BaseViewHolder>{




    public NewsAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public BaseViewHolder onCreateVH(ViewGroup parent, int viewType) {
        ViewDataBinding dataBinding = DataBindingUtil.inflate(inflater, R.layout.item_news,parent,false);
        return new BaseViewHolder(dataBinding);
    }

    @Override
    public void onBindView(BaseViewHolder holder, int positoin) {
        ViewDataBinding dataBinding = holder.getmBinding();
        dataBinding.setVariable(BR.newsbean,mList.get(positoin));
        dataBinding.setVariable(BR.position,positoin);
        dataBinding.setVariable(BR.adapter,this);
        dataBinding.executePendingBindings(); //防止闪烁
    }


    /**
     *
     * 点赞
     *
     * @param newsBeanSimple
     * @param position
     */



    public void clickDianZan(NewsBeanSimple newsBeanSimple,int position){

        if (newsBeanSimple.isGood.get()){
            newsBeanSimple.isGood.set(false);
        }else {
            newsBeanSimple.isGood.set(true);
        }

    }


















}
